package com.system.vote.admin.mapper;

import com.system.vote.admin.entity.TVote;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.system.vote.admin.entity.TWxUserinfo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author Administrator
 * @description 针对表【t_vote(投票表)】的数据库操作Mapper
 * @createDate 2023-10-26 17:20:40
 * @Entity com.system.vote.admin.entity.TVote
 */
public interface TVoteMapper extends BaseMapper<TVote> {

    @Select("SELECT id,nick_name,avatar_url,last_login_date,STATUS,register_date,phone,email " +
            "FROM t_wx_userinfo WHERE id IN ( SELECT w_uid FROM t_vote_detail WHERE vote_item_id=${id}) " +
            "order by last_login_date DESC  limit #{pageNum},#{pageSize} ")
    public List<TWxUserinfo> getUserListByItemId(@Param("id") Long id, @Param("pageNum") Long pageNum, @Param("pageSize") Long pageSize);


    @Select("select count(*) as voting from t_vote where  vote_end_time>now() and id not in (select distinct(vote_id) from t_vote_detail where  w_uid=#{uid})")
    public int statisticsVoting(@Param("uid") Long uid);

    @Select("select count(*) as voting from t_vote where  vote_end_time<now() and id not in (select distinct(vote_id) from t_vote_detail where  w_uid=#{uid})")
    public int statisticsEndVote(@Param("uid") Long uid);

    @Select("select count(*) as voted from t_vote where id  in (select distinct(vote_id) from t_vote_detail where  w_uid=#{uid})")
    public int statisticsVoted(@Param("uid") Long uid);
}




